(function(){var e=window.BX;if(e.FileUploadAgent)return;e.FileUploadAgent=function(t){this.controller=!!t["controller"]?t["controller"]:null;this.inputName=!!t["inputName"]?t["inputName"]:null;this.urlUpload=!!t["urlUpload"]?t["urlUpload"]:null;this.urlShow=!!t["urlShow"]?t["urlShow"]:null;this.values=e.type.isArray(t["values"])?t["values"]:[];this.fileInputID=!!t["fileInput"]?t["fileInput"]:null;this.fileInputName=!!t["fileInputName"]?t["fileInputName"]:null;this.multiple=!!t["multiple"];this.placeholder=!!t["placeholder"]?t["placeholder"]:null;this.uploadDialog=!!t["uploadDialog"]?t["uploadDialog"]:null;this.msg=t["msg"];this.fileInput=null;this.uploadFile=null;this.droppedFiles=null;this.place=null;this.progress=null;this.progressPercent=.05;this.progressAnimation=null;this.parent=t;this.uploadResultShown=false;this.loaded=false;this.hAttachEvents=!!t["hAttachEvents"]?t["hAttachEvents"]:null;this.caller=!!t["caller"]?t["caller"]:null;this.classes=!!t["classes"]?t["classes"]:{uploaderParent:"",uploader:"",tpl_simple:"",tpl_extended:"",selector:"",selector_active:""};this.doc_prefix=!!t["doc_prefix"]?t["doc_prefix"]:"";if(!!t["mode"])this.SelectViewVariant(t["mode"]);this.id=this.getID();if(!this.parent._mkFileInput)this._mkFileInput();this.hUploaderChange=this.onUploaderChange.bind(this);if(!window.wduf_places)window.wduf_places={}};e.FileUploadAgent.prototype.Init=function(){if(e.type.isDomNode(this.fileInput)){this.fileInput=this.fileInput}else if(e.type.isDomNode(this.fileInputID)){this.fileInput=this.fileInputID}else if(this.fileInputID){this.fileInput=e(this.fileInputID)}if(this.fileInput){e.bind(this.fileInput,"change",this.hUploaderChange)}if(this.hAttachEvents&&e.type.isFunction(this.hAttachEvents)){this.hAttachEvents(this)}};e.FileUploadAgent.prototype.getID=function(){return(""+(new Date).getTime()).substr(6)};e.FileUploadAgent.prototype._mkClose=function(t){if(!t)return false;var i=null;var l=e.create("SPAN",{props:{className:"del-but"}});var s=e.findChild(t,{className:"loading"},true);var a=e.findChild(t,{className:"files-storage-block"},true);if(!!s)i=s;else if(!!a)i=a;if(!!i){e.bind(l,"click",this.StopUpload.bind(this,t));i.appendChild(l)}};e.FileUploadAgent.prototype._mkPlace=function(t,i){if(!i)i=t;if(i in window.wduf_places&&!!window.wduf_places[i]){this.place=window.wduf_places[i];this.progress=e.findChild(this.place,{className:"load-indicator"},true)}else{this.progress=e.create("SPAN",{props:{className:"load-indicator"},style:{width:"5%"},children:[e.create("SPAN",{props:{className:"load-number"},text:"5%"})]});var l=e.create("SPAN",{props:{className:"loading-wrap"},children:[e.create("SPAN",{props:{className:"loading"}}),this.progress]});this.place=e.create("TR",{children:[e.create("TD",{props:{className:"files-name"},children:[e.create("SPAN",{props:{className:"files-text"},children:[e.create("SPAN",{props:{className:"f-wrap"},text:t})]})]}),e.create("TD",{props:{className:"files-storage"},attrs:{colspan:"2"},children:[e.create("SPAN",{text:this.msg["loading"]+":"}),l]})]});this._mkClose(this.place);if(!this.multiple)this.placeholder.innerHTML="";this.placeholder.appendChild(this.place);window.wduf_places[i]=this.place}};e.FileUploadAgent.prototype._mkFileInput=function(t){var i=e.findChild(this.controller,{className:this.classes.uploaderParent},true);var l=e.findChild(i,{className:this.classes.uploader});if(l){e.remove(l)}var s={type:"file",size:"1"};if(this.multiple){s["multiple"]="multiple"}var a=e.create("INPUT",{props:{className:this.classes.uploader},attrs:s});this.fileInput=a;this.fileInput.name=this.fileInputName;i.appendChild(this.fileInput);if(this.hUploaderChange)e.bind(this.fileInput,"change",this.hUploaderChange);return this.fileInput};e.FileUploadAgent.prototype.onUploaderChange=function(t){if(!this.uploadDialog)return;e.onCustomEvent(this.controller.parentNode,"ChangeFileInput",[t,this.fileInput,this]);e.onCustomEvent(this,"ChangeFileInput",[t,this.fileInput,this]);this.uploadDialog.SetFileInput(this.fileInput);if(!!this.uploadDialog.dropbox){this.UploadDroppedFiles(this.fileInput.files)}else{this.uploadDialog.CallSubmit()}};e.FileUploadAgent.prototype.onUploadStart=function(e){var t=e.GetUploadFileName();if(!this.uploadDialog||e.id!=this.uploadDialog.id){return false}if(!this.place)this._mkPlace(t);if(!this.uploadFile){this._mkFileInput();var i=this.GetNewObject();i.LoadDialogs(this.dialogs)}this.uploadFile=null};e.FileUploadAgent.prototype.onProgress=function(t,i){if(isNaN(t))return;if(t>.9&&!i)t=.9;if(!e.fx){this.UpdateProgressIndicator(t)}else if(!this.progressAnimation){this.progressAnimation=new e.fx({start:this.progressPercent,finish:t,allowFloat:true,type:function(t){return(e.fx.RULES.accelerated(t)+e.fx.RULES.decelerated(t))/2},time:3,step:.01,callback:e.delegate((function(e){this.UpdateProgressIndicator(e)}),this)});this.progressAnimation.start()}else{this.progressAnimation.stop(true);this.progressAnimation.options.start=+this.progressPercent;this.progressAnimation.options.finish=+t;this.progressAnimation.__checkOptions();this.progressAnimation.start()}};e.FileUploadAgent.prototype.onUploadFinish=function(e){this.uploadResult=e;this.onProgress(2,true)};e.FileUploadAgent.prototype.UpdateProgressIndicator=function(t){if(this.progressPercent>t)return;var i=Math.ceil(t*100);if(i>100)i=100;e.style(this.progress,"width",i+"%");var l=e.findChild(this.progress,{className:"load-number"},true);l.innerHTML=i+"%";this.progressPercent=t;if(t>.9999){if(this.uploadResult&&!this.uploadResultShown){this.uploadResultShown=true;if(this.uploadResult.success){this.ShowUploadedFile()}else{if(!!this.uploadResult.messages)this.ShowUploadError(this.uploadResult.messages)}}}};e.FileUploadAgent.prototype.ShowAttachedFiles=function(){if(!this.values)return;var t=this.values.slice();var i=this.values.shift();if(!!i){if(e.type.isDomNode(i)){var l=i.id;var s=l.match(new RegExp(this.doc_prefix+"(\\d+)"));if(!!s){var a=s[1];this.BindLoadedFileControls(a,i)}}else{if(!i.element_id){i={element_id:i}}this.uploadResultArr=new Array;for(var o=0;o<t.length;o++){var n=t[o];if(typeof t[o]=="object"){n=t[o].element_id}this._mkPlace("",n);this.uploadResultArr[o]={element_id:t[o].element_id,element_url:t[o].element_url,element_name:t[o].element_name,place:this.place}}this.ShowUploadedFile(i);this.values=[]}}};e.FileUploadAgent.prototype.BindLoadedFileControls=function(t,i){if(!i||i.nodeName!=="TR"){return}this.place=i;this._mkClose(i);e.onCustomEvent(this.caller,"BindLoadedFileControls",[this,t]);this._clearPlace();setTimeout(e.delegate(this.ShowAttachedFiles,this),200)};e.FileUploadAgent.prototype.ShowUploadError=function(t){if(!!t){if(e.type.isArray(t))t=t.join("\n");t=t.replace("<br>","");e.remove(this.progress.parentNode);if(!!t){e.addClass(this.place,"error-load");while(this.place.cells.length>1)this.place.deleteCell(1);var i=this.place.insertCell(-1);i.setAttribute("colspan",2);i.appendChild(e.create("SPAN",{props:{className:"info-icon"}}));i.appendChild(e.create("SPAN",{props:{className:"error-text"},text:t}));this._mkClose(this.place)}}};e.FileUploadAgent.prototype.ShowUploadedFile=function(t){if(!!t)this.uploadResult=t;e.onCustomEvent(this.caller,"ShowUploadedFile",[this])};e.FileUploadAgent.prototype.AddRowToPlaceholder=function(t){var i=e.findChildren(this.placeholder,{tagName:"TR"},true);if(!!i){for(var l=0;l<i.length;l++){if(i[l]==this.place){var s=this.placeholder.insertRow(l);s.className=t.className;s.id=t.id;var a=e.findChildren(t,{tagName:"TD"},true);if(!!a){for(var o=0;o<a.length;o++){var n=s.insertCell(-1);n.className=a[o].className;n.innerHTML=a[o].innerHTML}}e.cleanNode(this.place,true);this._clearPlace();this._mkClose(s);setTimeout(e.delegate(this.ShowAttachedFiles,this),200);break}}}};e.FileUploadAgent.prototype.AddNodeToPlaceholder=function(t){e.cleanNode(this.place,true);this._clearPlace();var i=this.placeholder.parentNode.parentNode;i.appendChild(t)};e.FileUploadAgent.prototype._clearPlace=function(){for(var e in window.wduf_places){if(window.wduf_places[e]==this.place){window.wduf_places[e]=false}}this.place=null};e.FileUploadAgent.prototype.StopUpload=function(t){if(!t){return}e.onCustomEvent(this.caller,"StopUpload",[this,t]);e.hide(t);var i=t.id.match(new RegExp(this.doc_prefix+"(\\d+)"));if(!!i){var l=e("file-doc"+i[1]);if(l){e.remove(l)}}};e.FileUploadAgent.prototype.LoadScript=function(t,i){if(!i)i=e.DoNothing;if(!window.loaded_scripts)window.loaded_scripts=[];if(!e.util.in_array(t,window.loaded_scripts)){e.loadScript(t,i);window.loaded_scripts.push(t)}};e.FileUploadAgent.prototype.BindUploadEvents=function(t){this.LoadDialogsFinished();if(t.parentID!=this.id)return;this.uploadDialog=t;e.addCustomEvent(t,"uploadStart",e.delegate(this.onUploadStart,this));e.addCustomEvent(t,"progress",e.delegate(this.onProgress,this));e.addCustomEvent(t,"uploadFinish",e.delegate(this.onUploadFinish,this));if(!!this.parent.droppedFiles){for(var i=0;i<this.parent.droppedFiles.length;i++){if(!this.parent.droppedFiles[i].ready){this.parent.droppedFiles[i].ready=true;this.uploadFile=this.parent.droppedFiles[i];if(i<this.parent.droppedFiles.length){var l=this.GetNewObject(this.parent);l.LoadDialogs(this.dialogs)}break}if(!this.multiple)break}if(this.uploadFile){if(this.fileInput){e.unbind(this.fileInput,"change",this.hUploaderChange)}var s=this.uploadFile.fileName||this.uploadFile.name;this._mkPlace(s)}}if(!!this.uploadFile){this.uploadDialog.fileDropped=true;this.uploadDialog.UpdateListFiles([this.uploadFile])}};e.FileUploadAgent.prototype.UploadDroppedFiles=function(e){if(!this.uploadDialog)return;this.droppedFiles=e;if(e.length>0){for(var t=0;t<e.length;t++){this._mkPlace(e[t].fileName||e[t].name);if(!this.multiple)break}this.uploadDialog.SetFileInput(this.fileInput);this._mkFileInput()}var i=this.GetNewObject();i.LoadDialogs(this.dialogs)};e.FileUploadAgent.prototype.AddSelectedFiles=function(t){if(!!t&&e.type.isArray(t)&&t.length>0){for(var i in t){if(!e(this.doc_prefix+t.id)){this._mkPlace(t[i].name,t[i].id);var l={element_id:t[i].id,element_url:t[i].link};this.values.push(l)}}if(this.values.length>0){this.ShowAttachedFiles()}}};e.FileUploadAgent.prototype.Disable=function(){e.cleanNode(this.controller);this.controller.innerHTML=this.msg.access_denied};e.FileUploadAgent.prototype.LoadUploadDialog=function(){if(!!this.caller){this.caller.GetUploadDialog(this)}};e.FileUploadAgent.prototype.SelectViewVariant=function(t){var i={simple:this.classes.tpl_simple,extended:this.classes.tpl_extended};for(var l in i){var s=e.findChild(this.controller,{className:i[l]},true);if(!!s){if(t==l)e.show(s);else e.remove(s)}}};e.FileUploadAgent.prototype.LoadDialogsFinished=function(){this.ShowAttachedFiles()};e.FileUploadAgent.prototype.LoadDialogs=function(t){if(this.loaded)return false;this.loaded=true;if(!t)return false;this.dialogs=t;if(t.indexOf("DropInterface")>-1&&(!this.parent||!this.parent.droppedFiles)){if(!!window.BX.DD){var i=this.controller;if(!i)return false;var l=new e.DD.dropFiles(i);if(l&&l.supported()&&e.ajax.FormData.isSupported()){this.dropbox=l;this.Init();var s=e.findChild(this.controller,{className:this.classes.selector},true);e.addCustomEvent(l,"dropFiles",e.delegate(this.UploadDroppedFiles,this));e.addCustomEvent(l,"dragEnter",e.delegate((function(){e.addClass(s,this.classes.selector_active)}),this));e.addCustomEvent(l,"dragLeave",e.delegate((function(){e.removeClass(s,this.classes.selector_active)}),this))}else{this.Init()}this.LoadUploadDialog()}}else{this.LoadUploadDialog()}if(this.values.length>0)e.show(this.controller)};e.FileUploadAgent.prototype.GetNewObject=function(t){return new e.FileUploadAgent(!!t?t:this)}})();
//# sourceMappingURL=file_upload_agent.map.js